#ifndef MMBBMS_SERVICE_H_INCL
#define MMBBMS_SERVICE_H_INCL

/*!
 * \file mmbbms_service.h
 *
 * \brief service infomation header file.
 *
 *
 *
 * \ingroup Core
 *
 * \par Include files
 * -
 *
 * \par Copyright (c) 2010 Maxscend Technologies Inc. All rights reserved
 *
 * PROPRIETARY RIGHTS of Maxscend Technologies Inc. are involved in
 * the subject matter of this material.  All manufacturing, reproduction,
 * use, and sales rights pertaining to this subject matter are governed
 * by the license agreement.  The recipient of this software implicitly
 * accepts the terms of the license.
 *
 * \version
 * Revision of last commit: $Rev:                             $
 * Author of last commit  : $Author:                          $
 * Date of last commit    : $Date:                            $
 *
 * \par History
 * $Log: mmbbms_service.h$
 * $Rev: $ $Author:  $ $Date: $
 * Formal Release Ver:
 * - Draft version
 */
#ifndef __cplusplus
#error this header requires C++ compiler
#endif

#include "mmbbms_serv_def.h"
#include "mmbbms_event.h"

class MMBBMS_Service
{
public:

    // ----------------------------------------------------------------------------------------
    // Inner type definition.
    // ----------------------------------------------------------------------------------------

    // Preference is used to control the inner running mechanism.

    struct Preference
    {
        enum
        {
            MMBBMS_ENV_UNKNOWN = 0, // Unknown environment.
            MMBBMS_ENV_GSM = 1,     // GSM environment.
            MMBBMS_ENV_3G = 2           // 3G environment.
        };

        // Telephone type.
        int m_eEnvType;

        // Adventure.
        // In some situations, PurchaseChannel needs to be specified.
        const char *m_pPurchaseChannelId;

        // The interval of change of stream key.
        unsigned int m_streamKeyInterval;

        // GPRS network connection setting.
        const char *m_pApn;     // APN
        const char *m_pWapGateway;  // WAP Gateway Domain
        int m_wapPort;          // WAP Gateway Port

        // Setting for MBBMS procedures.
        const char *m_pNafID;       // NAF Server ID
        const char *m_pNafDomain;   // NAF Server Domain
        const char *m_pSgDomain;    // SG Server Domain

        int m_nafPort;          // NAF Server Port
        int m_sgPort;               // SG Server Port
    };

    enum ACTIVATE_TYPE
    {
        REGISTER_ACTIVATION = 0,
        CANCELLATION_ACTIVATION = 1,
        PAUSE_ACTIVATION = 2,
        RESUME_ACTIVATION = 3,
        CHANGE_USER_PROFILE_ACTIVATION = 4
    };

public:
    // ----------------------------------------------------------------------------------------
    // API Functions related with general function.
    // ----------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------
    // API Functions related with SGDD.
    // ----------------------------------------------------------------------------------------
    /*
     * Get SGDD in local Service Guide
     * @return SG_SGDDBrief* - a pointer to the SG_SGDDBrief
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     */
    virtual SG_SGDDBrief *GetSGDDBrief() = 0;
    /*
     * Set lisenter for the MTV Service.
     * @param listener - the listenser of MTV service for callback usage.
     * \After a process finishes, the listener will be called.
     * @param cookie - the data passed to the listener.
     * \note - Synchronous function, only support 1 listener
     */

    virtual void SetCallback(void * cbFunc) = 0;

    /*
     * Used to set preference of MTV Service.
     * @param preference - the object of Preference.
     * @return int - the result of success or failure.
     * \0, successfully.
     * \-1, failed.
     * \note - Synchronous function
     * \The function should be called once the settings are changed every time.
     */
    virtual int SetPreference(Preference const &preference) = 0;

    // ----------------------------------------------------------------------------------------
    // API Functions related with ServiceGuide.
    // ----------------------------------------------------------------------------------------
    /*
     * Get all Service in local Service Guide
     * @return SG_ServiceBrief* - a pointer to all ServiceBriefs
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     */
    virtual SG_ServiceBrief *GetAllServiceBrief() = 0;

    /*
     * Get a complete Service.
     * @param serviceID - a Service ID
     * @return Service* - a pointer to a Service
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     * \The function is usually used to get detail information of a Service.
     */
    virtual SG_Service * GetService(const char *serviceID) = 0;

    /*
     * Get Access information of CMMB of a Service
     * @param serviceID - a Service id
     * @return char* - a formatted string of access information
     * \the format of access information:
     * \mbbms://cmmb?freqdot=&serviceid=&CAS_ID=&protected=&sdptxt=
     * \Parameters:
     * \freqdot, serial number of frequency dot.
     * \serviceid, service id of CMMB in a frequency dot.
     * \CAS_ID, ID of BSMSelector in SGDD.
     * \protected, flag of protected or not.
     * \sdptxt, content of a SDP.
     * \note - Synchronous function
     * \The string returned need to be freed.
     */
    virtual char *GetCMMBAccess(const char *serviceID) = 0;

    /*
     * Get all brief Content of a Service
     * @param serviceID - the service id
     * @return SG_ContentBrief* - a pointer to several ContentBriefs.
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     */
    virtual SG_ContentBrief *GetAllContentBrief(const char *serviceID) = 0;

    /*
     * Search all Content in terms of Keywords, Service ID, time interval, Genre.
     * @param key - Keywords
     * @param serviceId - a Service ID
     * @param from - start time in a time interval
     * @param to - end time in a time interval
     * @param genre - the type of Content
     * @return Content* - a pointer to several BriefConents
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     * \"key" must not be null, others may be null.
     * \The values of "from" and "to" are as same as time_t.
     * \If "from" or "to" is 0, the condition of "from" or "to" will be ignored.
     */
    virtual SG_ContentBrief *SearchContent(const char *key,
                                           const char *serviceId,
                                           unsigned long from,
                                           unsigned long to,
                                           const char *genre) = 0;

    /*
     * Get a complete Content.
     * @param contentID - a Content ID
     * @return SG_Content* - a pointer to a SG_Content
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     * \The function is usually used to get detail information of a Content.
     */
    virtual SG_Content * GetContent(const char *contentID) = 0;

    /*
     * Get all PurchaseChannels
     * @return SG_PurchaseChannel* - a pointer to several PurchaseChannels.
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     */
    virtual SG_PurchaseChannel * GetAllPurchaseChannel() = 0;

    /*
     * Get all PurchaseItems by Service category
     * @return SG_PurchaseItemBrief* - a pointer to several PurchaseItem.
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     * \The function is often used for subscription of a channel in a month.
     */
    virtual SG_PurchaseItemBrief *GetPurchaseItemByService() = 0;

    /*
     * Get all PurchaseItems of Contents which belongs to a Service.
     * @param serviceID - a Service id
     * @return SG_PurchaseItemBrief* - a pointer to several PurchaseItems
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     * \The function is often used for subscription of a program only in a short time interval.
     */
    virtual SG_PurchaseItemBrief *GetPurchaseItemByContent(const char
            *serviceID) = 0;

    /*
     * Get PurchaseItem by bundle category.
     * @return SG_PurchaseItemBrief* - a pointer to several PurchaseItems.
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     * \The function is often used for subscription of several channels or programs together.
     */
    virtual SG_PurchaseItemBrief *GetPurchaseItemByBundle() = 0;

    /*
     * Get all PurchaseItems related to a Service.
     * @param id - a Service ID
     * @return SG_PurchaseItemBrief* - head pointer of several PurchaseItemBriefs
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     */
    virtual SG_PurchaseItemBrief *GetPurchaseItemOfService(const char *id) =
        0;

    /*
     * Get all PurchaseItems related to a Content.
     * @param id - a Content ID
     * @return SG_PurchaseItemBrief* - head pointer of several PurchaseItemBriefs
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     */
    virtual SG_PurchaseItemBrief *GetPurchaseItemOfContent(const char *id) =
        0;

    /*
     * Get all sub-PurchaseItems related to a PurchaseItem.
     * @param id - a PurchaseItem ID
     * @return SG_PurchaseItemBrief* - head pointer of several PurchaseItemBriefs
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     * \The function is used for get what is in a PurchaseItem, especially those of a bundle type.
     */
    virtual SG_PurchaseItemBrief *GetSubPurchaseItem(const char
            *purchaseItemID) = 0;

    /*
     * Search all PurchaseItems in terms of Keywords, Service ID.
     * @param key - keywords
     * @param serviceID - a Service ID
     * @return SG_PurchaseItemBrief* - head pointer of several PurchaseItemBriefs
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     * \"key" must not be null, others may be null.
     */
    virtual SG_PurchaseItemBrief *SearchPurchaseItem(const char *key,
            const char *serviceID) =
                0;

    /*
     * Update the latest Service Guide from server to local.
     * @return int - always return 0
     * \note - Asynchronous function
     */
    virtual int StartUpdateServiceGuide() = 0;

    /*
     * Todo - Stop while updating Service Guide.
     * @return int - always return 0
     * \note - Asynchronous function
     */
    virtual int StopUpdateServiceGuide() = 0;

    // ----------------------------------------------------------------------------------------
    // API Functions related with transaction.
    // ----------------------------------------------------------------------------------------

    /*
     * Execute inquiry process to update my subscription information
     * @return int - always return 0
     * \note - Asynchronous function
     * \After it finishes, call "getAllSubscriptions" to get my subscription.
     */
    virtual int Inquiry(int value) = 0;

    /*
     * Get all PurchaseItems of subscribed Service and Content in local.
     * @return SG_PurchaseItemBrief* - a pointer to several PurchaseItemBriefs;
     * \note - Synchronous function
     * \The pointer returned need to be freed.
     * \The function should be called after "inquiry" is finished.
     */

    virtual SG_PurchaseItemBrief *GetAllSubscriptions() = 0;

    /*
     * Execute subscription process to subscribe several PurchaseItems.
     * @param purchaseID - a pointer of several globalPurchaseitemID
     * @param length - the length of the array.
     * @return int - always return 0
     * \note - Asynchronous function
     */
    virtual int Subscribe(const char *const purchaseID[], int length) = 0;

    /*
     * Execute unsubscribe process to unsubscribe several PurchaseItems.
     * @param purchaseID - a pointer of several globalPurchaseitemID
     * @param length - the length of the array.
     * @return int - always return 0
     * \note - Asynchronous function
     */
    virtual int Unsubscribe(const char *const purchaseID[], int length) =
        0;

    /*
     * Execute unsubscribe process to unsubscribe all PurchaseItems subscribed.
     * @return int - always return 0
     * \note - Asynchronous function
     */
    virtual int UnsubscribeAll() = 0;

    /*
     * Update the latest subscription information table from server to local
     * @return int - always return 0
     * \note - Asynchronous function
     * \The function should be called when subscription is finished or a new startup.
     */
    virtual int UpdateSubscriptionTable() = 0;

    // ----------------------------------------------------------------------------------------
    // API Functions related with security.
    // ----------------------------------------------------------------------------------------

    /*
     * Execute GBA bootstrap process
     * @param force - a flag if needs to force to start an GBA procedure.
     * \Default it is not.
     * @return int - always return 0
     * \note - Asynchronous function
     * \The function should be called when a new startup.
     */
    virtual int Initialize(int force = 0) = 0;

    /*
     * Execute activation process
     * @param type - the type of activation.
     * \REGISTER_ACTIVATION, register MTV service.
     * \CANCELLATION_ACTIVATION, cancel MTV service.
     * \PAUSE_ACTIVATION, pause MTV service.
     * \RESUME_ACTIVATION, resume MTV service.
     * \CHANGE_USER_PROFILE_ACTIVATION, change the user profile for MTV service.
     * @return int - always return 0
     * \note - Asynchronous function
     */
    virtual int Activate(ACTIVATE_TYPE type) = 0;
#if 0
    /*
     * Execute authorization process
     * @param sms - a string of a SMS of WAP PUSH.
     * @return int - always return 0
     * \note - Asynchronous function
     * \The function is used when a WAP push SMS is coming.
     */
    virtual int Authorize(const char *sms) = 0;
#endif
    /*
     * Execute authorization process of A Service
     * @param serviceID - Service ID.
     * @return int - result of authorization.
     * \0, executing authorization process;
     * \1, authorization process has been already finished.
     * \note - Asynchronous function
     * \The function is used before trying to play a Service,
     * \if it returns 0, the player needs to wait until the service key is retrieved.
     */
    virtual int AuthorizeService(const char *serviceID) = 0;

    MMBBMS_Service();

    virtual ~ MMBBMS_Service();
};

/*
 * Increase reference count of the instance of MMBBMS Service
 * @return MTV_Service* - a pointer to a MTV_Service
 * \note - Synchronous function
 * \Only an instance exists, in spite of the function can be called repeatedly.
 */
EXTERN MMBBMS_Service *MMBBMS_CreateService();

/*
 * Decrease reference count of the instance of MMBBMS Service
 * @param MTV_Service*& - a pointer to a MMBBMS_Service
 * \note - Synchronous function
 * If the reference count is 0, the instance will be released.
 */
EXTERN void MMBBMS_DestroyService(MMBBMS_Service * &pService);

/*
 * Set MBBMS Protocol Data Path
 * @param path - path to store MBBMS protocol datas
 * @param image_path - path to store MBBMS protocol pictures which may be equal with path.
 * @return void
 * \note - Synchronous function
 * This function should be called at the beginning, and only once.
 */
extern "C" void MMBBMS_SetDataPath(const char *path);
/*
 * Set MBBMS SG Data change flag
 * @status - the status for sg change for nor
 *
 * @return void
 * \note - Synchronous function
 * This function should be called at the beginning, and only once.
 */
extern "C" void MMBBMS_GetSGChanged(void*  status);

#endif                          // end of #ifndef MMBBMS_SERVICE_H_INCL
